/**
 * Demo :	Demo class for HashCode
 * 
 * @langversion		HaXe 2
 * @targets			cpp, flash, flash9, js, neko, php
 * @author			Justin Donaldson
 * @since			2010-02-05
 */
class Demo {
	public function new(){
		
	}
	public static function main(){
		var int = 12; //integer
		var str = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; //string
		var flt = 0.0; //float
		var an = {x:100}; // anonymous
		#if flash9
		var mc = new flash.display.MovieClip();
		trace("flash specific hashing");
		trace(HashCode.getHash(mc));
		#elseif flash
/*			too lazy to do a demo here.*/
		#end
		trace("generic hashing");
		trace(HashCode.getHash(int));
		trace(HashCode.getHash(12.01));
		trace(HashCode.getHash(12.01));
		trace(HashCode.getHash(str));
		var an2 = an;
		trace("closures?");
		var f = function(){return 1;}
		var f2 = function(){return 2;}
		trace(HashCode.getHash(f));
		trace(HashCode.getHash(f2));
		trace("basic class object equivalence");
		var b = new Bar();
		var b2 = new Bar();
		trace(HashCode.getHash(b));
		trace(HashCode.getHash(b2));		
		trace(HashCode.getHash(b2));
		trace("arrays");
		var arr = [1,2,3,4];
		trace(HashCode.getHash([1,2,3,4]));
		trace(HashCode.getHash([1,2,3,4]));
		trace(HashCode.getHash([1,2,3,4]));
		trace(HashCode.getHash(arr));
		var arr2 = arr;
		trace(HashCode.getHash(arr2));	
		return;	
		trace("anonymous object hash equivalence");
		trace(HashCode.getHash(an2));
		trace(HashCode.getHash(an));
		trace("custom object hash equivalence");
		var f = new Foo(5);
		var f2 = new Foo(5);
		trace(f == f2);
		trace(HashCode.getHash(f) == HashCode.getHash(f2));
		
		trace(HashCode.getHash(b));
		trace('getting rid of the __id field from a Reflection call');
		trace(Reflect.fields(f));
		trace(HashCode.fields(f));
	}
}

/**
 * Foo :	An example class that implements the IHashCode interface.  The hash code
 *  is set to "x" when the "x" field is initialized.
 * 
 * @langversion		HaXe 2
 * @targets			cpp, flash, flash9, js, neko, php
 * @author			Justin Donaldson
 * @since			2010-02-05
 */
class Foo implements HashCode.IHashCode
{
	var __id:Int;
	var x:Int;
	public function new(x:Int){
		this.x = x;
		this.__id = x;
	}
	
}

class Bar{
	public function new(){}
}
